package com.agileboot.domain.performance.score.query;

import cn.hutool.core.util.StrUtil;
import com.agileboot.common.core.page.AbstractPageQuery;
import com.agileboot.domain.performance.score.db.UserScoreRecordEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.math.BigDecimal;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 用户分数记录查询类
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class UserScoreRecordQuery extends AbstractPageQuery<UserScoreRecordEntity> {

    private Long userId;
    private Integer assessmentYear;
    private Long deptId;
    private BigDecimal researchWorkload;
    private BigDecimal teachingWorkload;
    private BigDecimal educationWorkload;
    private BigDecimal serviceWorkload;
    private BigDecimal otherWorkload;
    private BigDecimal generalCourseScore;
    private BigDecimal majorCourseScore;
    private BigDecimal labCourseScore;
    private BigDecimal pendingScore;
    private BigDecimal approvedTotalScore;

    @Override
    public QueryWrapper<UserScoreRecordEntity> addQueryCondition() {
        QueryWrapper<UserScoreRecordEntity> queryWrapper = new QueryWrapper<UserScoreRecordEntity>()
                .eq(userId != null, "user_id", userId)
                .ge(researchWorkload != null, "research_workload", researchWorkload)
                .ge(teachingWorkload != null, "teaching_workload", teachingWorkload)
                .ge(educationWorkload != null, "education_workload", educationWorkload)
                .ge(serviceWorkload != null, "service_workload", serviceWorkload)
                .ge(otherWorkload != null, "other_workload", otherWorkload)
                .ge(generalCourseScore != null, "general_course_score", generalCourseScore)
                .ge(majorCourseScore != null, "major_course_score", majorCourseScore)
                .ge(labCourseScore != null, "lab_course_score", labCourseScore)
                .ge(pendingScore != null, "pending_score", pendingScore)
                .ge(approvedTotalScore != null, "approved_total_score", approvedTotalScore)
                .eq(assessmentYear != null, "assessment_year", assessmentYear)
                .eq(deptId != null, "dept_id", deptId);

        // 默认排序字段，如果没有指定排序字段则按create_time排序
        if (StrUtil.isEmpty(this.getOrderColumn())) {
            this.setOrderColumn("create_time");
        }
        this.setTimeRangeColumn("create_time");

        return queryWrapper;
    }
}

